//
//  AKEntry.h
//  CocoaBean
//
//  Created by sleeper on 5/18/10.
//  Copyright 2010 __MyCompany__ All rights reserved.
//

#import <Foundation/Foundation.h>

enum {
	AKEntryCategoryUnkown = -1,
	AKEntryCategoryUndefined = 0,
	AKEntryCategorySaying,			// http://www.douban.com/2007#miniblog.saying
	
	AKEntryCategoryBook,			// http://www.douban.com/2007#miniblog.book
	AKEntryCategoryMagazine,
	AKEntryCategoryMovie,
	AKEntryCategoryTv,
	AKEntryCategoryMusic,
	
	AKEntryCategoryPlace,			// http://www.douban.com/2007#miniblog.place
	AKEntryCategoryGroup,			// http://www.douban.com/2007#miniblog.group
	
	AKEntryCategoryEvent,			// http://www.douban.com/2007#miniblog.event
	
	AKEntryCategorySite,			// http://www.douban.com/2007#miniblog.site
	AKEntryCategoryRecommendation,	// http://www.douban.com/2007#miniblog.recommendation
	AKEntryCategoryNote,			// http://www.douban.com/2007#miniblog.note
	AKEntryCategoryBlog,			// http://www.douban.com/2007#miniblog.blog
	
	AKEntryCategoryPhoto,			// http://www.douban.com/2007#miniblog.photo
	
	AKEntryCategoryContact,			// http://www.douban.com/2007#miniblog.contact
	AKEntryCategoryPlaza,			// http://www.douban.com/2007#miniblog.plaza
	AKEntryCategorySignature		// http://www.douban.com/2007#miniblog.signature
};
typedef NSInteger AKEntryCategory;

enum {
	AKEntryContentImageTypeNone = 0,
	AKEntryContentImageTypeSquare,
	AKEntryContentImageTypeRectangle  // 4:3
};
typedef NSUInteger AKEntryContentImageType;

@interface AKEntry : NSObject <NSCoding> {
	AKEntryCategory _type;
	
	// For categories
	NSString *_title;
	
	NSString *_relatedURL;
	NSString *_imageURL;
	NSString *_alternateURL;
	NSString *_selfURL;
	
	BOOL _checkedTags;
	NSArray *_tagNames;
	NSArray *_tagCounts;
	
	NSArray *_authors;
	
	NSDictionary *_dictionary;
	NSString *_entryIdURL;
	NSString *_entryId;
}

+ (NSArray*)entriesWithDictionaries:(NSArray*)dictionaries;
- (id)initWithDictionary:(NSDictionary*)dictionary;

@property (nonatomic, readonly) NSString *entryIdURL;
@property (nonatomic, readonly) NSString *entryId;

@property (nonatomic, readonly) NSString *categoryString;
@property (nonatomic, readonly) AKEntryCategory category;

@property (nonatomic, copy, readonly) NSDictionary *dictionary;

@end

// AKMiniblogEntry, AKMediaEntry
@interface AKEntry (Title)
@property (nonatomic, readonly) NSString *title;
@end

@interface AKEntry (Link)
// AKMiniblogEntry, AKMediaEntry
@property (nonatomic, readonly) NSString *imageURL;
// AKMiniblogEntry
@property (nonatomic, readonly) NSString *relatedURL;
// AKMediaEntry
@property (nonatomic, readonly) NSString *selfURL;		
@property (nonatomic, readonly) NSString *alternateURL;
@end

// AKMediaEntry
@interface AKEntry (Tags)
@property (nonatomic, readonly) NSUInteger numberOfTagNames;
- (NSString *)tagNameAtIndex:(NSUInteger)index;
- (NSInteger)numberOfTagsAtIndex:(NSUInteger)index;
@end

// AKMediaEntry
@interface AKEntry (Rating)
@property (nonatomic, readonly) float ratingAverage;
@property (nonatomic, readonly) float ratingMax;
@property (nonatomic, readonly) float ratingMin;
@property (nonatomic, readonly) NSInteger numberOfRaters;
@end

// AKMediaEntry
@interface AKEntry (Authors)
@property (nonatomic, readonly) NSArray *authors;
@end

static inline AKEntryContentImageType AKEntryGetContentImageType(AKEntryCategory entryCategory)
{
	switch (entryCategory) {
		case AKEntryCategoryBook:
		case AKEntryCategoryMovie: 
		case AKEntryCategoryMagazine:
			return AKEntryContentImageTypeRectangle;
		case AKEntryCategoryMusic:
		case AKEntryCategoryPhoto:
			return AKEntryContentImageTypeSquare;
		default:
			return AKEntryContentImageTypeNone;
	}
}
